import 'package:flutter/material.dart';

/*常用的颜色常量*/
class ConstThemeColors {
  static const Color title = Color.fromRGBO(28, 30, 33, 1.0);
  static const Color darkTitle = Color.fromRGBO(237, 240, 242, 1.0);

  static const Color primaryText = Color.fromRGBO(68, 71, 74, 1.0);
  static const Color darkPrimaryText = Color.fromRGBO(206, 209, 212, 1.0);

  static const Color secondText = Color.fromRGBO(120, 119, 125, 1.0);
  static const Color darkSecondText = Color.fromRGBO(148, 150, 153, 1.0);

  static const Color disable = Color.fromRGBO(176, 178, 180, 1.0);
  static const Color darkDisable = Color.fromRGBO(92, 94, 96, 1.0);

  static const Color divide = Color.fromRGBO(222, 224, 226, 1.0);
  static const Color darkDivide = Color.fromRGBO(36, 38, 40, 1.0);

  static const Color bg = Colors.white;
  static const Color darkBg = Colors.black;

  static const Color cellBg = Color.fromRGBO(252, 252, 252, 1.0);
  static const Color darkCellBg = Color.fromRGBO(6, 10, 15, 1.0);

  static const Color red = Colors.red;
  static const Color darkRed = Colors.redAccent;

  static const Color blue = Colors.blue;
  static const Color darkBlue = Colors.lightBlueAccent;
}

/*UI界面调用的颜色对象*/
enum AppThemeColor {
  title,
  primaryText,
  secondText,
  disable,
  divide,
  bg,
  cellBg,
  red,
  blue,
}
extension AppThemeColorValue on AppThemeColor {
  Color value(BuildContext context) {
    bool isDark = isDarkMode(context);
    switch(this) {
      case AppThemeColor.title:
        return isDark ? ConstThemeColors.darkTitle : ConstThemeColors.title;
      case AppThemeColor.primaryText:
        return isDark ? ConstThemeColors.darkPrimaryText : ConstThemeColors.primaryText;
      case AppThemeColor.secondText:
        return isDark ? ConstThemeColors.darkSecondText : ConstThemeColors.secondText;
      case AppThemeColor.disable:
        return isDark ? ConstThemeColors.darkDisable : ConstThemeColors.disable;
      case AppThemeColor.divide:
        return isDark ? ConstThemeColors.darkDivide : ConstThemeColors.divide;
      case AppThemeColor.bg:
        return isDark ? ConstThemeColors.darkBg : ConstThemeColors.bg;
      case AppThemeColor.cellBg:
        return isDark ? ConstThemeColors.darkCellBg : ConstThemeColors.cellBg;
      case AppThemeColor.red:
        return isDark ? ConstThemeColors.darkRed : ConstThemeColors.red;
      case AppThemeColor.blue:
        return isDark ? ConstThemeColors.darkBlue : ConstThemeColors.blue;
      default:
        return Colors.black;
    }
  }

  bool isDarkMode(BuildContext context){
    return Theme.of(context).brightness == Brightness.dark;
  }
}